package ooday03;
/** 引用类型数组的演示 */
public class RefArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("哈士奇",2,"灰白");
        dogs[1] = new Dog("萨摩耶", 4, "白");
        dogs[2] = new Dog("阿拉斯加", 3, "黑白");
        //输出第一只狗狗的名字
        System.out.println(dogs[0].name);

        dogs[1].age=5;//修改第二只狗狗的年龄为四岁
        dogs[2].color="灰条白";
        dogs[2].swim();
        for (int i = 0; i < dogs.length; i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("公鸡", 2, "红");
        chicks[1] = new Chick("母鸡", 1, "黄");
        for(int i = 0; i < chicks.length; i++){
            System.out.println(chicks[i].color);
            chicks[i].layEggs();
        }

        Fish[] fish = new Fish[3];
        fish[0] = new Fish("罗非", 2, "灰");
        fish[1] = new Fish("鲢鳙", 1,"浅灰");
        fish[2] = new Fish("海豚", 3, "白");
        for(int i=0; i< fish.length; i++){
            System.out.println(fish[i].name);
            System.out.println(fish[i].color);
            fish[i].swim();
        }

        /*
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("哈士奇",2,"灰白");
        dogs[1] = new Dog("萨摩耶", 4, "白");
        dogs[2] = new Dog("阿拉斯加", 3, "黑白");

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("公鸡", 2, "红");
        chicks[1] = new Chick("母鸡", 3, "黄");
         */

        /*
        //声明Dog型数组dogs，包含3个元素，每个元素都是Dog型, 默认值为null
        Dog[] dogs = new Dog[3];
        //声明chick型数组chicks，包含3个元素，每个元素都是Chick型，默认值为null
        Chick[] chick = new Chick[3];
        //声明Fish型数组fish，包含2个元素，每个元素都是Fish型
        Fish[] fish = new Fish[2];
         */
    }
}
